package com.zh.common.utils

import android.view.View
import com.zh.common.R

object DoubleUtils {

    private val TIME: Long = 800
    private var lastClickTime2: Long = 0

    fun isFastDoubleClick(): Boolean {
        val time = System.currentTimeMillis()
        if (time - lastClickTime2 < TIME) {
            return true
        }
        lastClickTime2 = time
        return false
    }

    fun isFastDoubleClick(view: View): Boolean {
        var lastClickTime = view.getTag(R.id.last_click_time)
        if (EmptyUtils.isEmpty(lastClickTime)) lastClickTime = 0L

        val currentTime = System.currentTimeMillis()
        val time = currentTime - (lastClickTime as? Long ?: 0L)
        if (time < TIME) {
            return true
        }
        lastClickTime = currentTime
        view.setTag(R.id.last_click_time, lastClickTime)
        return false
    }
}